﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmbeddedLanguage
{
    public static class TypeEx
    {
        public static T GetAttribute<T>(this Type typ) where T : Attribute
        {
            var attribs = typ.GetCustomAttributes(typeof(T), true);
            if (attribs == null || attribs.Length == 0) return default(T);
            return attribs[0] as T;
        }

        public static List<T> GetAttributes<T>(this Type typ) where T : Attribute
        {
            var returnObj = new List<T>();
            var attribs = typ.GetCustomAttributes(typeof(T), true);
            if (attribs == null || attribs.Length == 0) return returnObj;
            foreach (var attrib in attribs)
            {
                returnObj.Add(attrib as T);
            }
            return returnObj;
        }
    }
}
